% Generator: GNU source-highlight, by Lorenzo Bettini, http://www.gnu.org/software/src-highlite

{\ttfamily \raggedright {
\noindent
\mbox{}\textbf{\textcolor{RoyalBlue}{\#include}}\ \texttt{\textcolor{Red}{$<$vector$>$}} \\
\mbox{}\textbf{\textcolor{RoyalBlue}{\#include}}\ \texttt{\textcolor{Red}{$<$set$>$}} \\
\mbox{}\textbf{\textcolor{RoyalBlue}{\#include}}\ \texttt{\textcolor{Red}{$<$map$>$}} \\
\mbox{}\textbf{\textcolor{RoyalBlue}{\#include}}\ \texttt{\textcolor{Red}{$<$algorithm$>$}} \\
\mbox{}\textbf{\textcolor{RoyalBlue}{\#include}}\ \texttt{\textcolor{Red}{$<$iostream$>$}} \\
\mbox{}\textbf{\textcolor{RoyalBlue}{\#include}}\ \texttt{\textcolor{Red}{$<$iterator$>$}} \\
\mbox{} \\
\mbox{}\textbf{\textcolor{Blue}{using}}\ \textbf{\textcolor{Blue}{namespace}}\ std\textcolor{BrickRed}{;} \\
\mbox{} \\
\mbox{}\textbf{\textcolor{Blue}{typedef}}\ string\ node\textcolor{BrickRed}{;} \\
\mbox{}\textbf{\textcolor{Blue}{typedef}}\ map\textcolor{BrickRed}{$<$}node\textcolor{BrickRed}{,}\ vector\textcolor{BrickRed}{$<$}node\textcolor{BrickRed}{$>$}\ \textcolor{BrickRed}{$>$}\ graph\textcolor{BrickRed}{;} \\
\mbox{}\textbf{\textcolor{Blue}{typedef}}\ \textcolor{ForestGreen}{char}\ color\textcolor{BrickRed}{;} \\
\mbox{} \\
\mbox{}\textbf{\textcolor{Blue}{const}}\ color\ WHITE\ \textcolor{BrickRed}{=}\ \textcolor{Purple}{0}\textcolor{BrickRed}{,}\ GRAY\ \textcolor{BrickRed}{=}\ \textcolor{Purple}{1}\textcolor{BrickRed}{,}\ BLACK\ \textcolor{BrickRed}{=}\ \textcolor{Purple}{2}\textcolor{BrickRed}{;} \\
\mbox{} \\
\mbox{}graph\ g\textcolor{BrickRed}{;} \\
\mbox{}map\textcolor{BrickRed}{$<$}node\textcolor{BrickRed}{,}\ color\textcolor{BrickRed}{$>$}\ colors\textcolor{BrickRed}{;} \\
\mbox{}map\textcolor{BrickRed}{$<$}node\textcolor{BrickRed}{,}\ \textcolor{ForestGreen}{int}\textcolor{BrickRed}{$>$}\ d\textcolor{BrickRed}{,}\ low\textcolor{BrickRed}{;} \\
\mbox{} \\
\mbox{}set\textcolor{BrickRed}{$<$}node\textcolor{BrickRed}{$>$}\ cameras\textcolor{BrickRed}{;} \\
\mbox{} \\
\mbox{}\textcolor{ForestGreen}{int}\ timeCount\textcolor{BrickRed}{;} \\
\mbox{} \\
\mbox{}\textcolor{ForestGreen}{void}\ \textbf{\textcolor{Black}{dfs}}\textcolor{BrickRed}{(}node\ v\textcolor{BrickRed}{,}\ \textcolor{ForestGreen}{bool}\ isRoot\ \textcolor{BrickRed}{=}\ \textbf{\textcolor{Blue}{true}}\textcolor{BrickRed}{)}\textcolor{Red}{\{} \\
\mbox{}\ \ colors\textcolor{BrickRed}{[}v\textcolor{BrickRed}{]}\ \textcolor{BrickRed}{=}\ GRAY\textcolor{BrickRed}{;} \\
\mbox{}\ \ d\textcolor{BrickRed}{[}v\textcolor{BrickRed}{]}\ \textcolor{BrickRed}{=}\ low\textcolor{BrickRed}{[}v\textcolor{BrickRed}{]}\ \textcolor{BrickRed}{=}\ \textcolor{BrickRed}{++}timeCount\textcolor{BrickRed}{;} \\
\mbox{}\ \ vector\textcolor{BrickRed}{$<$}node\textcolor{BrickRed}{$>$}\ neighbors\ \textcolor{BrickRed}{=}\ g\textcolor{BrickRed}{[}v\textcolor{BrickRed}{];} \\
\mbox{}\ \ \textcolor{ForestGreen}{int}\ count\ \textcolor{BrickRed}{=}\ \textcolor{Purple}{0}\textcolor{BrickRed}{;} \\
\mbox{}\ \ \textbf{\textcolor{Blue}{for}}\ \textcolor{BrickRed}{(}\textcolor{ForestGreen}{int}\ i\textcolor{BrickRed}{=}\textcolor{Purple}{0}\textcolor{BrickRed}{;}\ i\textcolor{BrickRed}{$<$}neighbors\textcolor{BrickRed}{.}\textbf{\textcolor{Black}{size}}\textcolor{BrickRed}{();}\ \textcolor{BrickRed}{++}i\textcolor{BrickRed}{)}\textcolor{Red}{\{} \\
\mbox{}\ \ \ \ \textbf{\textcolor{Blue}{if}}\ \textcolor{BrickRed}{(}colors\textcolor{BrickRed}{[}neighbors\textcolor{BrickRed}{[}i\textcolor{BrickRed}{]]}\ \textcolor{BrickRed}{==}\ WHITE\textcolor{BrickRed}{)}\textcolor{Red}{\{}\ \textit{\textcolor{Brown}{//\ \ (v,\ neighbors[i])\ is\ a\ tree\ edge}} \\
\mbox{}\ \ \ \ \ \ \textbf{\textcolor{Black}{dfs}}\textcolor{BrickRed}{(}neighbors\textcolor{BrickRed}{[}i\textcolor{BrickRed}{],}\ \textbf{\textcolor{Blue}{false}}\textcolor{BrickRed}{);} \\
\mbox{}\ \ \ \ \ \ \textbf{\textcolor{Blue}{if}}\ \textcolor{BrickRed}{(!}isRoot\ \textcolor{BrickRed}{\&\&}\ low\textcolor{BrickRed}{[}neighbors\textcolor{BrickRed}{[}i\textcolor{BrickRed}{]]}\ \textcolor{BrickRed}{$>$=}\ d\textcolor{BrickRed}{[}v\textcolor{BrickRed}{])}\textcolor{Red}{\{} \\
\mbox{}\ \ \ \ \ \ \ \ cameras\textcolor{BrickRed}{.}\textbf{\textcolor{Black}{insert}}\textcolor{BrickRed}{(}v\textcolor{BrickRed}{);} \\
\mbox{}\ \ \ \ \ \ \textcolor{Red}{\}} \\
\mbox{}\ \ \ \ \ \ low\textcolor{BrickRed}{[}v\textcolor{BrickRed}{]}\ \textcolor{BrickRed}{=}\ \textbf{\textcolor{Black}{min}}\textcolor{BrickRed}{(}low\textcolor{BrickRed}{[}v\textcolor{BrickRed}{],}\ low\textcolor{BrickRed}{[}neighbors\textcolor{BrickRed}{[}i\textcolor{BrickRed}{]]);} \\
\mbox{}\ \ \ \ \ \ \textcolor{BrickRed}{++}count\textcolor{BrickRed}{;} \\
\mbox{}\ \ \ \ \textcolor{Red}{\}}\textbf{\textcolor{Blue}{else}}\textcolor{Red}{\{}\ \textit{\textcolor{Brown}{//\ (v,\ neighbors[i])\ is\ a\ back\ edge}} \\
\mbox{}\ \ \ \ \ \ low\textcolor{BrickRed}{[}v\textcolor{BrickRed}{]}\ \textcolor{BrickRed}{=}\ \textbf{\textcolor{Black}{min}}\textcolor{BrickRed}{(}low\textcolor{BrickRed}{[}v\textcolor{BrickRed}{],}\ d\textcolor{BrickRed}{[}neighbors\textcolor{BrickRed}{[}i\textcolor{BrickRed}{]]);} \\
\mbox{}\ \ \ \ \textcolor{Red}{\}} \\
\mbox{}\ \ \textcolor{Red}{\}} \\
\mbox{}\ \ \textbf{\textcolor{Blue}{if}}\ \textcolor{BrickRed}{(}isRoot\ \textcolor{BrickRed}{\&\&}\ count\ \textcolor{BrickRed}{$>$}\ \textcolor{Purple}{1}\textcolor{BrickRed}{)}\textcolor{Red}{\{}\ \textit{\textcolor{Brown}{//Is\ root\ and\ has\ two\ neighbors\ in\ the\ DFS-tree}} \\
\mbox{}\ \ \ \ cameras\textcolor{BrickRed}{.}\textbf{\textcolor{Black}{insert}}\textcolor{BrickRed}{(}v\textcolor{BrickRed}{);} \\
\mbox{}\ \ \textcolor{Red}{\}} \\
\mbox{}\ \ colors\textcolor{BrickRed}{[}v\textcolor{BrickRed}{]}\ \textcolor{BrickRed}{=}\ BLACK\textcolor{BrickRed}{;} \\
\mbox{}\textcolor{Red}{\}} \\
\mbox{} \\
\mbox{}\textcolor{ForestGreen}{int}\ \textbf{\textcolor{Black}{main}}\textcolor{BrickRed}{()}\textcolor{Red}{\{} \\
\mbox{}\ \ \textcolor{ForestGreen}{int}\ n\textcolor{BrickRed}{;} \\
\mbox{}\ \ \textcolor{ForestGreen}{int}\ map\ \textcolor{BrickRed}{=}\ \textcolor{Purple}{1}\textcolor{BrickRed}{;} \\
\mbox{}\ \ \textbf{\textcolor{Blue}{while}}\ \textcolor{BrickRed}{(}cin\ \textcolor{BrickRed}{$>$$>$}\ n\ \textcolor{BrickRed}{\&\&}\ n\ \textcolor{BrickRed}{$>$}\ \textcolor{Purple}{0}\textcolor{BrickRed}{)}\textcolor{Red}{\{} \\
\mbox{}\ \ \ \ \textbf{\textcolor{Blue}{if}}\ \textcolor{BrickRed}{(}map\ \textcolor{BrickRed}{$>$}\ \textcolor{Purple}{1}\textcolor{BrickRed}{)}\ cout\ \textcolor{BrickRed}{$<$$<$}\ endl\textcolor{BrickRed}{;} \\
\mbox{}\ \ \ \ g\textcolor{BrickRed}{.}\textbf{\textcolor{Black}{clear}}\textcolor{BrickRed}{();} \\
\mbox{}\ \ \ \ colors\textcolor{BrickRed}{.}\textbf{\textcolor{Black}{clear}}\textcolor{BrickRed}{();} \\
\mbox{}\ \ \ \ d\textcolor{BrickRed}{.}\textbf{\textcolor{Black}{clear}}\textcolor{BrickRed}{();} \\
\mbox{}\ \ \ \ low\textcolor{BrickRed}{.}\textbf{\textcolor{Black}{clear}}\textcolor{BrickRed}{();} \\
\mbox{}\ \ \ \ timeCount\ \textcolor{BrickRed}{=}\ \textcolor{Purple}{0}\textcolor{BrickRed}{;} \\
\mbox{}\ \ \ \ \textbf{\textcolor{Blue}{while}}\ \textcolor{BrickRed}{(}n\textcolor{BrickRed}{-\/-)}\textcolor{Red}{\{} \\
\mbox{}\ \ \ \ \ \ node\ v\textcolor{BrickRed}{;} \\
\mbox{}\ \ \ \ \ \ cin\ \textcolor{BrickRed}{$>$$>$}\ v\textcolor{BrickRed}{;} \\
\mbox{}\ \ \ \ \ \ colors\textcolor{BrickRed}{[}v\textcolor{BrickRed}{]}\ \textcolor{BrickRed}{=}\ WHITE\textcolor{BrickRed}{;} \\
\mbox{}\ \ \ \ \ \ g\textcolor{BrickRed}{[}v\textcolor{BrickRed}{]}\ \textcolor{BrickRed}{=}\ vector\textcolor{BrickRed}{$<$}node\textcolor{BrickRed}{$>$();} \\
\mbox{}\ \ \ \ \textcolor{Red}{\}} \\
\mbox{}\ \ \ \  \\
\mbox{}\ \ \ \ cin\ \textcolor{BrickRed}{$>$$>$}\ n\textcolor{BrickRed}{;} \\
\mbox{}\ \ \ \ \textbf{\textcolor{Blue}{while}}\ \textcolor{BrickRed}{(}n\textcolor{BrickRed}{-\/-)}\textcolor{Red}{\{} \\
\mbox{}\ \ \ \ \ \ node\ v\textcolor{BrickRed}{,}u\textcolor{BrickRed}{;} \\
\mbox{}\ \ \ \ \ \ cin\ \textcolor{BrickRed}{$>$$>$}\ v\ \textcolor{BrickRed}{$>$$>$}\ u\textcolor{BrickRed}{;} \\
\mbox{}\ \ \ \ \ \ g\textcolor{BrickRed}{[}v\textcolor{BrickRed}{].}\textbf{\textcolor{Black}{push$\_$back}}\textcolor{BrickRed}{(}u\textcolor{BrickRed}{);} \\
\mbox{}\ \ \ \ \ \ g\textcolor{BrickRed}{[}u\textcolor{BrickRed}{].}\textbf{\textcolor{Black}{push$\_$back}}\textcolor{BrickRed}{(}v\textcolor{BrickRed}{);} \\
\mbox{}\ \ \ \ \textcolor{Red}{\}} \\
\mbox{}\ \ \ \  \\
\mbox{}\ \ \ \ cameras\textcolor{BrickRed}{.}\textbf{\textcolor{Black}{clear}}\textcolor{BrickRed}{();} \\
\mbox{}\ \ \ \  \\
\mbox{}\ \ \ \ \textbf{\textcolor{Blue}{for}}\ \textcolor{BrickRed}{(}graph\textcolor{BrickRed}{::}iterator\ i\ \textcolor{BrickRed}{=}\ g\textcolor{BrickRed}{.}\textbf{\textcolor{Black}{begin}}\textcolor{BrickRed}{();}\ i\ \textcolor{BrickRed}{!=}\ g\textcolor{BrickRed}{.}\textbf{\textcolor{Black}{end}}\textcolor{BrickRed}{();}\ \textcolor{BrickRed}{++}i\textcolor{BrickRed}{)}\textcolor{Red}{\{} \\
\mbox{}\ \ \ \ \ \ \textbf{\textcolor{Blue}{if}}\ \textcolor{BrickRed}{(}colors\textcolor{BrickRed}{[(*}i\textcolor{BrickRed}{).}first\textcolor{BrickRed}{]}\ \textcolor{BrickRed}{==}\ WHITE\textcolor{BrickRed}{)}\textcolor{Red}{\{} \\
\mbox{}\ \ \ \ \ \ \ \ \textbf{\textcolor{Black}{dfs}}\textcolor{BrickRed}{((*}i\textcolor{BrickRed}{).}first\textcolor{BrickRed}{);} \\
\mbox{}\ \ \ \ \ \ \textcolor{Red}{\}} \\
\mbox{}\ \ \ \ \textcolor{Red}{\}} \\
\mbox{}\ \ \ \ \ \  \\
\mbox{}\ \ \ \ cout\ \textcolor{BrickRed}{$<$$<$}\ \texttt{\textcolor{Red}{"{}City\ map\ \#"{}}}\textcolor{BrickRed}{$<$$<$}map\textcolor{BrickRed}{$<$$<$}\texttt{\textcolor{Red}{"{}:\ "{}}}\ \textcolor{BrickRed}{$<$$<$}\ cameras\textcolor{BrickRed}{.}\textbf{\textcolor{Black}{size}}\textcolor{BrickRed}{()}\ \textcolor{BrickRed}{$<$$<$}\ \texttt{\textcolor{Red}{"{}\ camera(s)\ found"{}}}\ \textcolor{BrickRed}{$<$$<$}\ endl\textcolor{BrickRed}{;} \\
\mbox{}\ \ \ \ \textbf{\textcolor{Black}{copy}}\textcolor{BrickRed}{(}cameras\textcolor{BrickRed}{.}\textbf{\textcolor{Black}{begin}}\textcolor{BrickRed}{(),}\ cameras\textcolor{BrickRed}{.}\textbf{\textcolor{Black}{end}}\textcolor{BrickRed}{(),}\ ostream$\_$iterator\textcolor{BrickRed}{$<$}node\textcolor{BrickRed}{$>$(}cout\textcolor{BrickRed}{,}\texttt{\textcolor{Red}{"{}}}\texttt{\textcolor{CarnationPink}{\textbackslash{}n}}\texttt{\textcolor{Red}{"{}}}\textcolor{BrickRed}{));} \\
\mbox{}\ \ \ \ \textcolor{BrickRed}{++}map\textcolor{BrickRed}{;} \\
\mbox{}\ \ \textcolor{Red}{\}} \\
\mbox{}\ \ \textbf{\textcolor{Blue}{return}}\ \textcolor{Purple}{0}\textcolor{BrickRed}{;} \\
\mbox{}\textcolor{Red}{\}} \\

} \normalfont\normalsize
